import { Body, Controller, Get, Post, Query } from "@nestjs/common";
import { DeptService } from "./dept.service";
import { ApiTags } from "@nestjs/swagger";
import { ReqAddDeptDto, ReqDeptListDto, ReqUpdateDeptDto } from "./dto/req-dept.dto";
import { DataObj } from "src/common/class/data-obj.class";

@ApiTags("部门管理")
@Controller("system/dept")
export class DeptController {
  constructor(private readonly deptService: DeptService) {}

  @Get("getDeptList")
  async getList(@Query() reqDeptListDto: ReqDeptListDto) {
    const deptArr = await this.deptService.getDeptList(reqDeptListDto);
    return DataObj.create(deptArr);
  }

  @Post("addDept")
  async addDept(@Body() reqAddDeptDto: ReqAddDeptDto) {
    await this.deptService.addOrUpdate(reqAddDeptDto);
  }

  // 编辑部门
  @Post("editDept")
  async editDept(@Body() reqUpdateDeptDto: ReqUpdateDeptDto) {
    await this.deptService.addOrUpdate(reqUpdateDeptDto);
  }

  // 删除部门
  @Post("deleteDept")
  async deleteDept(@Body("dept_id") dept_id: string) {
    await this.deptService.deleteDeptById(dept_id);
  }
}
